$(function(){
 			$('#dg').datagrid({    
   			 url:'admin/question/listRows', 
   			 toolbar:'#tb',
   			 fit:true, 
   			 border:false,
   			 rownumbers:true,
   			 singleSelect:false,
   			 checkOnSelect:true,
   			 autoRowHeight:false,
   			 loadMsg:'加载中，请稍等...',
   			striped:true,//显示斑马线
   			idField:'id',//翻页时记住前面选的
   			pagination:true,//显示底部分页工具栏
   			pageSize:10,
   			pageList:[10,20,30,40,50],
  			columns:[[
  						 { field:'ck',checkbox:true },
		       			 {field:'id',title:'ID',width:'10%',sortable:true,hidden:true},    
		       			 {field:'questionTitle',title:'标题',width:'20%'},    
		       			 {field:'questionKeyword',title:'关键词',width:'15%'},    
		       			 {field:'questionClick',title:'点击量',width:'5%'},    
		       			 {field:'questionCollection',title:'收藏数',width:'5%'},    
		       			 {field:'questionAbout',title:'点赞数',width:'5%'},    
		       			 {field:'questionIntegral',title:'悬赏分数',width:'5%'},    
		       			 {field:'questionLevel',title:'等级',width:'5%'},    
		       			 {field:'isFin',title:'是否结束',width:'5%'},    
		       			 {field:'questionAnswerCount',title:'回答数',width:'5%', 
		       				 formatter: function(value,row,index){
		       					 var aHref= "<a href=\"javascript:void(0);\"  style=\"color:red;font-weight: true;text-decoration:underline;\" onclick=\"showComment();\">"+value+"</a>";
		       					 return aHref;
		       			 }},    
		       			 {field:'questionDetail',title:'问题详情',width:'26%'}
  		  					]]    
					}); 
 			});
 			
	var url = "";
	// 新增用户对话框
    function add(){
    	$("#fm").form('clear');
    	$("#dlg").dialog("open").dialog("setTitle","添加用户信息");
    	url = 'admin/question/save';
    }

	// 修改用户对话框
    function edit(){
		var rows=$("#dg").datagrid('getSelections');
		if(rows.length !=1){
			$.messager.alert('系统提示','请选择一条要编辑的数据！');
			return;
		}
		var row=rows[0];
		$("#dlg").dialog("open").dialog("setTitle","修改用户信息");
		$("#fm").form("load",row);
		url = 'admin/question/edit?id='+row.id;
	}
	
    // 关闭添加修改对话框
    function closeDialog(){
    	$("#fm").form('clear');
    	$("#dlg").dialog("close");
    }

/**
    * 刷新
 */
 function refresh(){
    $('#dg').datagrid('reload');
    $('#dg').datagrid('clearChecked');
  }
 
 /*显示评论*/
 function showComment(){
	 	var row = $('#dg').datagrid('getSelected');
	 	$('#dlg-comment-table').datagrid({
	 		 fit:true, 
   			 border:false,
   			 rownumbers:true,
   			 singleSelect:false,
   			 checkOnSelect:true,
   			 autoRowHeight:false,
   			 loadMsg:'加载中，请稍等...',
   			striped:true,//显示斑马线
		 	idField:'id',//翻页时记住前面选的
			pagination:true,//显示底部分页工具栏
			pageSize:10,
			pageList:[10,20,30,40,50],   
		    url:'admin/question/listCommentsByQuestionId?questionId='+row.id,    
		    columns:[[    
		        { field:'ck',checkbox:true },
		       	{field:'id',title:'ID',width:'5%',sortable:true,hidden:true},    
		        {field:'chName',title:'用户',width:'15%', 
		        	formatter: function(value,row,index){
		        	return row.user.chName;
		        }},    
		        {field:'questionAnswer',title:'评论',width:'55%'},    
		        {field:'createDate',title:'时间',width:'20%',align:'right',
		         formatter: function(value,row,index){
		        		 if(value != null){
	       			  			return formatDate(value);
	       			  		}
       			 }}
		    ]]    
		}); 
	 	$("#dlg-comment").dialog("open").dialog("setTitle","查看评论").dialog("modal","true");
 }
 
 /**
 *删除
 */
 function del(){
 		var row = $('#dg').datagrid('getSelected');
		$.messager.confirm('确认','您确认想要删除记录吗？',function(r){    
		if (r){    
				$.ajax({
					type:'POST',
					url:'admin/question/deleteById',
					data:{id:row.id},
					dataType:'json',
					success:function(data){
							if(data && data.success){
								parent.$.messager.show({
											title:'提示',
											msg:data.message
										});
										$('#dg').datagrid('unselectAll'); 
											$('#dg').datagrid('reload'); 
							}else{
								parent.$.messager.alert('提示',data.message);
							}
						}
								});
						    }    
						}); 
 			} 
 			
 function saveOrEdit(){
	 $.ajax({
			type:'POST',
			url:url,
			data:$('#fm').serialize(),
			dataType:'json',
			success:function(data){
					if(data && data.success){
								$('#dlg').dialog('close');
								parent.$.messager.show({
									title:'提示',
									msg:data.message
								});
								$('#dg').datagrid('unselectAll'); 
								$('#dg').datagrid('reload'); 
					}else{
						parent.$.messager.alert('提示',data.message);
					}
			},
			error:function(data){
				parent.$.messager.alert('提示',data.message);
			}
	 });
 }
 
